using Godot;
using System.Collections.Generic;
using TopDownGodot.Src.Models.DTO;

namespace TopDownGodot.Src.Globals.Multiplayer
{
    public partial class MultiplayerGlobal : Node
    {
        // 已加入全局自动加载
        [Signal]
        public delegate void SendCharacterIdEventHandler(int characterId); // Renamed to follow naming convention

        public static bool IsMultiplayer { get; set; } = false; // 当前是否是多人模式
        public static int PlayerChoicesCharacterId { get; set; } = 1; // 初始化选择角色id
        internal static List<RoomInfoDTO> RoomInfo { get; set; }

        public static void OnSendCharacterId(int characterId)
        {
            PlayerChoicesCharacterId = characterId;
        }

        public override void _Notification(int what)
        {
            if (what == NotificationWMWindowFocusOut)
            {
                if (GetTree() != null)
                {
                    GD.Print("Close the game");
                    GetTree().Quit();
                }
                else
                {
                    GD.Print("警告: GetTree() 为 null，无法退出。");
                }
            }
        }
    }
}